package com.prs.crm.action.oa;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.oa.ReadyWritePermissionSet;
import com.prs.crm.service.oa.ReadyWritePermissionSetService;

/**
 * @author YangHao
 * @E-Mail:450098606@qq.com
 * @qq:450098606
 * @version 创建时间：2012-5-10 11:00:38 读写权限设置
 */
public class ReadyWritePermissionSetAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private ReadyWritePermissionSet readyWritePermissionSet;
	private ReadyWritePermissionSetService readyWritePermissionSetService;
	private PaginationSupport pagination;
	private Integer[] ids;
	public ReadyWritePermissionSet getReadyWritePermissionSet() {
		return readyWritePermissionSet;
	}
	public void setReadyWritePermissionSet(
			ReadyWritePermissionSet readyWritePermissionSet) {
		this.readyWritePermissionSet = readyWritePermissionSet;
	}

	public ReadyWritePermissionSetService getReadyWritePermissionSetService() {
		return readyWritePermissionSetService;
	}
	public void setReadyWritePermissionSetService(
			ReadyWritePermissionSetService readyWritePermissionSetService) {
		this.readyWritePermissionSetService = readyWritePermissionSetService;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	@Action("listReadyWritePermissionSet")
	public String listReadyWritePermissionSet(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(ReadyWritePermissionSet.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getReadyWritePermissionSetService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editReadyWritePermissionSet")
	public String editReadyWritePermissionSet(){
		return SUCCESS;
	}
	
	@Action(value = "saveReadyWritePermissionSet", results = {
			@Result(name = "success", type = "redirect", location = "listReadyWritePermissionSet"),
			@Result(name = "error", type = "chain", location = "editReadyWritePermissionSet"),
		 })
	public String saveReadyWritePermissionSet(){
		this.getReadyWritePermissionSetService().save(readyWritePermissionSet);
		return SUCCESS;
	}
	
	@Action(value = "removeReadyWritePermissionSet", results = {
			@Result(name = "success", type = "redirect", location = "listReadyWritePermissionSet"),
			@Result(name = "error", type = "chain", location = "listReadyWritePermissionSet"),
		 })
	public String removeReadyWritePermissionSet(){
		if (ids==null) {
			this.addActionError("请选择一行进行操作");
			return ERROR;
		}
		this.getReadyWritePermissionSetService().batchRemove(ids);
		return SUCCESS;
	}
}
